<template>
  <el-table :data="data" @selection-change="getSelected">
    <el-table-column type="selection" width="55"/>
    <slot/>
  </el-table>
</template>

<script>
  export default {
    name: "SelectionTable",
    props: {
      keys: {
        type: Array,
        default: () => []
      },
      strings: {
        type: Array,
        default: () => []
      },
      data: {
        type: Array,
        default: () => []
      },
      rowKey: {
        type: String,
        default: "id"
      }
    },
    methods: {
      getSelected(array) {
        this.$emit("update:keys", array.map(item => item[this.rowKey]))
        let orderList = []
        array.forEach(item => {
          if (Object.prototype.hasOwnProperty.call(item, 'number')) {
            orderList.push(item.number)
          }
        })
        if (orderList.length !== 0) {
          this.$emit("update:strings", orderList)
        }
      }
    }
  }
</script>
